package com.xur.springboot.controller;

import com.xur.springboot.entity.Companies;
import com.xur.springboot.mapper.CompaniesMapper;
import com.xur.springboot.service.CompaniesService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CompaniesController {

    @Resource
    private CompaniesService CompaniesService;
    //在鸿蒙前端获取数据时需要解析JSON数据
    //直接返回json数据
    @GetMapping("/companies")
    public List<Companies> companies(){
        System.out.println("查询了公司信息列表");
        return CompaniesService.queryAllCompanies();

    }


    @GetMapping("/companiesByCom_id")
    public List<Companies> queryComByCom_id(@RequestParam int com_id){
        System.out.println("根据com_id查询了公司信息,com_id:" + com_id);
        return CompaniesService.queryComByCom_id(com_id);

    }

    @GetMapping("/searchCom")
    public ResponseEntity<List<Companies>> searchCompanies(@RequestParam String keyword) {
        List<Companies> results = CompaniesService.searchCompanies(keyword);
        System.out.println("对公司信息进行了模糊查询：" + keyword);
        return ResponseEntity.ok(results);
    }
}
